<template>
  <div>
    child2 - <button @click="fn">+</button> - <button @click="fn2">-</button>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
import { DECREMENT } from "../store/mutations-types";
export default {
  methods: {
    // 将仓库里面的mutations的函数映射到组件的methods里面
    ...mapMutations(["increment", DECREMENT]),
    fn() {
      // this.$store.commit("increment", { num: 3 });
      // 等价的
      // 对象风格的提交方式
      // this.$store.commit({
      //   type: "increment",
      //   num: 3,
      // });
      this.increment({ num: 3 });
    },
    fn2() {
      // this.$store.commit("decrement");
      this.decrement();
    },
  },
};
</script>

<style lang="less" scoped></style>
